package controllers

import (
	"fmt"
	"github.com/astaxie/beego/logs"
	"github.com/eclipse/paho.mqtt.golang"
	"smart_home/mqtt/system"
	"time"
)

type TimeNowController struct {
	system.Controller
}

func (c *TimeNowController) Exece(client mqtt.Client, message mqtt.Message, clientId string) {
	data := fmt.Sprintf(`{"time": %v}`, time.Now().Unix())
	token := client.Publish(clientId+"/time/now", 1, false, data)
	if err := token.Error(); err != nil {
		logs.Error(err)
	}
}
